package com.liveneo.system.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.liveneo.adapter.base.entity.PrpmOrg;
import com.liveneo.adapter.base.entity.PrpmOrgExample;
import com.liveneo.adapter.base.mapper.PrpmOrgMapper;
import com.liveneo.adapter.base.support.BaseService;
import com.liveneo.system.base.utils.Constant;

/**
 * 用户信息服务类
 */
@Service
public class OrgService extends BaseService<PrpmOrgMapper, PrpmOrg> {
    // 删除当前信息及其关联的所有子集
    public boolean delRelateChildren(List<String> ids) throws Exception {
        PrpmOrgExample example = new PrpmOrgExample();
        example.createCriteria().andIdIn(ids);
        int res = mapper.deleteByExample(example);
        return res > 0;
    }

    /**
     * 保存数据 id为空时，执行新增，id不为空，修改
     * @param entity
     * @return
     */
    public boolean save(PrpmOrg entity) throws Exception {
        // 判断Id是否为空
        // "               "
        int res = 0;
        if (StringUtils.isBlank(entity.getId())) {
            entity.setId(Constant.MYSQL_UUID);
            res = mapper.insert(entity);
        } else {
            entity.setOrgPid(entity.getOrgPid());
            res = mapper.updateByPrimaryKey(entity);
        }
        return res > 0;
    }

    public List<PrpmOrg> queryList(PrpmOrg prpmOrg) {
        return null;
    }
    
    public PrpmOrg selectByOrgCode(String orgCode){
    	return mapper.selectByOrgCode(orgCode);
    }
}
